<%@page import="org.apache.jasper.tagplugins.jstl.core.Redirect"%>
<%@page import="classes.Customer"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>Totalitea - Homepage</title>
		<jsp:useBean id="loginBean" class="beans.CustomerLoginBeanDAO" scope="page"></jsp:useBean>
		<jsp:useBean id="searchBean" class="beans.ProductBeanDAO" scope="page"></jsp:useBean>
		<meta name="tea" content="All the tea!">
		<link rel="stylesheet" href="main.css" type="text/css">
		<script type="text/javascript">
			function registerRedirect()
			{
				window.location.href("register.jsp");
			}
		</script>	
	</head>
	<body>
		<img class="banner" src="images/TotaliteaLogo.png">
        
        <ul class="navigationBar">
	        <li class="navigationBarList"><a id="activePage" class="navigationBarLink" href="index.jsp">Home</a></li>
	        <li class="navigationBarList"><a class="navigationBarLink" href="search.jsp">Search</a></li>
	        <li class="navigationBarList"><a class="navigationBarLink" href="basket.jsp">Basket</a></li>
	        <li class="navigationBarList"><a class="navigationBarLink" href="stockReport.jsp">Stock Report</a></li>
        </ul>
      	
        
        <%  
        if(loginBean.getLoginState() == false)
        {%>
        
	        <div class="loginForm" id="login">
	        	
		            <table>
		            	<form action=LoginServlet METHOD=GET name=indexLoginForm>
			            	<tr>
			            		<td> Username </td>
			            		<td> <input type="text" name="username"><br /> </td>
			            	</tr>
			            	<tr>
			                	<td> Password </td> 
			                	<td> <input type="password" name="password"> </td>
			                	<td> <input type="submit" value="Login"> </td>
			                </tr>
		                </form>
		                
		                <tr>
		                	<td> </td>
		                	<td> Not a member? </td>
		                	<td> <a href="register.jsp"><input type="button" value="Register" /></a> </td>
		                </tr>
		            </table>
	            
	        </div>
	        
	        <div id="login">
	            <form action=LoginServlet METHOD=GET name = indexLoginForm>
					<!-- Get the attributes from the login servlet and pass them to the bean to check against db -->
	                <% String username = (String) request.getSession().getAttribute("username"); %>
					<% String password = (String) request.getSession().getAttribute("password"); %>
					<% loginBean.getLogin(username, password); %>
					<% boolean loginState = loginBean.getLoginState(); %>
					<% boolean goldMember = false; %>
		        
		        <% 
				if(loginState == true)
				{
					goldMember = loginBean.getCustomer().getGoldMember();
					request.getSession().setAttribute("emailAddress", loginBean.getCustomer().getEmailAddress());
		        	
					if(loginBean.getCustomer().getUsername().equals("admin"))
					{
						%><font color="##0000FF"><b> ADMIN: Admin rights approved!</b></font><%
					}
					else if (loginBean.getCustomer().getGoldMember() == true)
					{
					%><font color="#CCCC00"><b> Gold Member: Welcome back <%= loginBean.getCustomer().getFirstName() %></b></font><%
					}
					else
					{
						%><b> Standard Member: Welcome back <%= loginBean.getCustomer().getFirstName() %></b><%
					}
					%>
					<input type="submit" value="Logout">
					<style>
					div.loginForm {
						display: none;
					}
					</style><%
				}
				%>
		        </form>
		   	</div>
	        
	        <div class="searchForm">
	            <form action="ResultsServlet" METHOD="GET" name="resultsPageForm1">
	            	<input type="hidden" name="search" value="1">
	                Search: <input type="search" name="searchQuery">
	                <input type="submit" value="Search">
	            </form>
	        </div>
        	<% 
        	request.getSession().setAttribute("loginState", loginState);
        	request.getSession().setAttribute("goldMember", goldMember);
        }%>
        <h1>Welcome to Totali<font color="#b5e61d">tea</font></h1>
        
        <table id="otherTables">
        	<tr>
        		<td> <img src="images/tea_lipton.png" alt="lipton tea"> </td>
        		<td> <img src="images/tea_sencha.png" alt="sencha tea"> </td>
        		<td> <img src="images/tea_yogi.png" alt="yogi energy tea">   </td>
        	</tr>
        </table>
        <ul class="navigationBar">
	        <li class="navigationBarList"><a class="teaBar" href="http://www.liptontea.com">Lipton</a></li><!-- placeholder link -->
	        <li class="navigationBarList"><a class="teaBar" href="http://en.wikipedia.org/wiki/Sencha">Sencha</a></li>
	        <li class="navigationBarList"><a class="teaBar" href="http://en.wikipedia.org/wiki/Yogi_Tea">Yogi</a></li><!-- placeholder link -->
        </ul>
        
        
	</body>
</html>